using UnityEngine;
using System.Collections;

public class CharacterStateToCover : CharacterState
{
	float m_fSpeedToCover = 20.0f;
	float m_fDistanceToGetThere = 0.5f;
	float m_fInitialDistance;
	
	public override void enter()
	{
		m_fInitialDistance = (c.vTargetPosition - c.getPos()).magnitude;
	}
	
	public override void update()
	{	
		Vector3 vMove = c.vTargetPosition - c.getPos();
		
		// check if character arrived
		if (vMove.magnitude < m_fDistanceToGetThere)
		{
			c.oController.Move(vMove);
			c.changeState<CharacterStateCoveringHigh>();
		}
		else
		{
			vMove.Normalize();
			vMove *= m_fSpeedToCover * Time.deltaTime;
			c.oController.Move(vMove);
		}
		
		c.updateVerticalPosition();
		
		if (!c.hasMoved())
		{
			c.changeState<CharacterStateStanding>();
		}
	}
	
	public override void exit()
	{
		sCovers.Instance.hitCover(m_fInitialDistance);
	}
}
